package cn.wolfcode.luowowo.website.web.controller;


import cn.wolfcode.luowowo.common.exception.LogicalException;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import cn.wolfcode.luowowo.common.util.AssertUtil;
import cn.wolfcode.luowowo.member.service.IUserinfoService;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.util.StringUtil;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class RegisterController {

    @Reference
    private IUserinfoService userinfoService;

    @RequestMapping("/checkPhone")
    @ResponseBody
    public Boolean checkPhone(String phone) {
        if(!StringUtil.isEmpty(phone)) {
            return !userinfoService.checkPhone(phone);
        }
        return null;
    }

    @RequestMapping("/sendVerifyCode")
    @ResponseBody
    public AjaxResult sendVerifyCode(String phone) {
        //将 验证码 手机号 创建时间 放到 redis层 里面
        if(StringUtil.isEmpty(phone)) {
            return new AjaxResult(false,"手机号不能为空");
        }
       userinfoService.sendVerifyCode(phone);
        return new AjaxResult();
    }

    @RequestMapping("/userRegist")
    @ResponseBody
    public AjaxResult userRegist(String phone,String nickname,String password,String rpassword,String verifyCode) {

            userinfoService.userRegist(phone,nickname,password,rpassword,verifyCode);
            return new AjaxResult();
    }}